<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
	#add_generalStorage .box p>label>span {
		display: inline-block;
		width: 50px;
		text-align: right;
	}
	
	#add_generalStorage input[type='text'],
	#add_generalStorage select {
		width: 125px
	}
	
	#add_generalStorage .formBox {
		padding: 0;
	}
</style>
<div class="modal fade" id="add_generalStorage" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 940px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增物品</h4>
			</div>
			<div class="box modal-body">
				<form id="searchItemForm">
					<p>
						<label> 
							<span class="must" style="width: 90px;">领料出库单号</span> 
							<input type="text" name="pickingNumber" class="form-control"></input>
							<span class="must">创建人</span> 
							<input type="text" name="createPersonName" class="form-control"></input>
							<span class="must" style="width: 65px;">提交时间</span> 
							<input type="text" name="commitTime1" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
							<span style="width: 5px;">-</span> 
							<input type="text" name="commitTime2" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
							
						</label>
						<input class="btn btn1" type="button" value="搜索" onclick="initItemTable();">
						<input class="btn btn2" type="button" value="清除" onclick="clearSearchParam();">
					</p>
				</form>
				<table id="add_item_table"></table>
			</div>
			<div class="red" id="add_purchase_request_item_msg" style="text-align: center;"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn_danger" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<script>
	//清空搜索条件
	function clearSearchParam() {
		$("#add_generalStorage input:text").val("");
		$("#add_generalStorage select").val("");
	}

	function toAddPurchaseRequestItem() {
		if($("#purchaseRequestItemTbody tr").length == 0) {
			selectPurchase();
		} else {
			Prompt.confirm("提示", "重新选择领料出库单将清除表格", selectPurchase, null);
		}

	}

	function selectPurchase() {
		$('#purchaseRequestItemTbody').empty(); /* 清空物品表格 */
		initItemTable();
		$('#add_generalStorage').modal('show');
	}

	function initItemTable() {
		var columns = [{
			field: "pickingID",
			title: "ID"
		}, {
			field: "pickingNumber",
			title: "领料出库编号"
		}, {
			field: "warehouseName",
			title: "仓库"
		}, {
			field: "status",
			title: "状态",
			formatter: function(value, row, index) {
				/* 0=未处理，1=处理中，2=已处理 */
				if(value == 0) {
					return '未提交';
				} else if(value == 1) {
					return '已提交';
				}
				return '';
			}
		}, {
			field: "commitTime",
			title: "提交时间",
			formatter: function(value, row, index) {
				var date = new Date();
				date.setTime(value);
				return date.format("yyyy-MM-dd HH:mm:ss");
			}
		}, {
			field: "createPersonName",
			title: "创建人"
		}, {
			field: 'operate',
			title: '操作',
			width: '80px',
			events: listMemberOperateEvent,
			formatter: listMemberOperate
		}];
		$("#add_item_table").bootstrapTable("destroy");
		$("#add_item_table").bootstrapTable({
			columns: columns,
			data: [],
			pageSize: 10,
			pageList: [10],
			pagination: true,
			clickToSelect: true,
			uniqueId: "id",
			sidePagination: 'server',
			pageNumber: 1,
			queryParams: function(params) {
				var pickingPage = params.offset / params.limit + 1;
				var str = $("#searchItemForm").serialize() +
					"&pickingPage=" + pickingPage +
					"&pageSize=" + params.limit +
					"&warehouseManagementID=" + $("#generalStorageForm select[name='warehouseID']  option:selected").val();
				return str;
			},
			url: '<%=basePath%>pickingReturnContrlooer/listAddItem'
		});
	}

	function listMemberOperate(value, row, index) {
		return ['<a class="addItem btn btn-xs btn1">添加</button>', ].join('');
	}

	window.listMemberOperateEvent = {
		'click .addItem': function(e, value, row, index) {
			addItem(row);
		}
	};

	function addItem(item) {
		$('#add_generalStorage').modal('hide');
		addToHasAddTable(item);
		$("#add_item_table").bootstrapTable('remove', {
			field: 'pickingID',
			values: [item.pickingID]
		});
	}
</script>